//
//  FocusOnTableViewController.m
//  TheRoadAD
//
//  Created by baixue on 16/8/15.
//  Copyright © 2016年 baixue. All rights reserved.
//

#import "FocusOnTableViewController.h"
#import "FocusOnCell.h"
#import "HeaderFocus.h"

@interface FocusOnTableViewController ()<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
{
    UIView *_line;
    UIScrollView *_scrollerView;
}
@property (nonatomic, strong) UITableView *tableView;
@end

static NSString *const FOCUS = @"focus";
@implementation FocusOnTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"关注";
    //导航右编辑按钮
    UIBarButtonItem *search = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_home_meitu_2"] style:UIBarButtonItemStylePlain target:self action:@selector(searchItem)];
    self.navigationItem.rightBarButtonItem = search;
     [self setUpHeader];
    [self setTableViewWithCount:0];
    [self setTableViewWithCount:1];
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
}


-(void)searchItem{
    NSLog(@"搜索");
}


-(void)setTableViewWithCount:(NSInteger)count{
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(Screen_Width * count, 0, Screen_Width, _scrollerView.size.height) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor whiteColor];
    [_scrollerView addSubview:_tableView];
    
    [_tableView registerNib:[UINib nibWithNibName:@"FocusOnCell" bundle:nil] forCellReuseIdentifier:FOCUS];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 5;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    FocusOnCell *cell = [tableView dequeueReusableCellWithIdentifier:FOCUS];
    
    return cell;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 60 * Screen_Height/734;
}

//添加headerView
-(void)setUpHeader{
    HeaderFocus *headerView = [[HeaderFocus alloc] initWithFrame:CGRectMake(0, 0, Screen_Width, Screen_Height)];
    _line = headerView.line;
    _scrollerView = headerView.scrollerView;
    _scrollerView.delegate = self;
    [self.view addSubview:headerView];
    headerView.SelectBlock = ^(NSInteger tag){
        [UIView animateWithDuration:0.25 animations:^{
            
            _line.frame = CGRectMake(Screen_Width/2*(tag-125)+60, 45, Screen_Width/2-120, 3);
            _scrollerView.contentOffset = CGPointMake(Screen_Width*(tag-125), 0);
        }];
    };
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    NSInteger index = _scrollerView.contentOffset.x/Screen_Width;
    [UIView animateWithDuration:0.25 animations:^{
        _line.frame = CGRectMake(Screen_Width/2*index +60, 45, Screen_Width/2-120, 3);
    }];
}

//获取我的关注
-(void)GetConcern{
    //URL：http://114.215.172.41:7756/Concern/GetConcern
    NSDictionary *para = @{
                           @"Concern":@"",
                           @"PageSize":@"",
                           @"":@""
                           };
}

@end
